package utils;

import org.apache.poi.hssf.usermodel.HSSFCell;

public class POIUtil {

	public static String getStringValue(HSSFCell celda) {

		if (celda != null) {
			if (celda.getCellType() == HSSFCell.CELL_TYPE_STRING) {
				return celda.getStringCellValue();
			} else if (celda.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
				return String.valueOf((int) celda.getNumericCellValue());
			}
		}
		return null;
	}

	public static Double getDoubleValue(HSSFCell celda) {
		if (celda != null) {
			if (celda.getCellType() == HSSFCell.CELL_TYPE_STRING) {
				try {
					return Double.parseDouble(celda.getStringCellValue());
				} catch (NumberFormatException e) {
					return null;
				}

			} else if (celda.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
				return celda.getNumericCellValue();
			}
		}
		return null;
	}

	public static Integer getIntegerValue(HSSFCell celda) {
		if (celda != null) {
			if (celda.getCellType() == HSSFCell.CELL_TYPE_STRING) {
				try {
					return Integer.parseInt(celda.getStringCellValue());
				} catch (NumberFormatException e) {
					return null;
				}

			} else if (celda.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
				return Integer.valueOf(new Double(celda.getNumericCellValue())
						.intValue());
			}
		}
		return null;
	}

}
